package link;

import offer.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class leetCode144_preorderTraversal {

    public List<Integer> ans = new ArrayList<>();
    public List<Integer> preorderTraversal(TreeNode root) {
        if(root == null) return ans;
        build(root);
        return ans;
    }

    public void build(TreeNode root){
        if(root == null) return;
        ans.add(root.val);
        build(root.left);
        build(root.right);
    }

}
